// pages/experience/index.js
var app = getApp();
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		startTime: '2001.09.01',
		endTime: '2005.09.01',
		level: '', //所有的学历选项
		levelIdx: 0, //默认学历
		major: '',
		idx: '',
		schoolName: ''
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		console.log('options:',options);
		var pages = getCurrentPages(); //当前页面
		var perPage = pages[pages.length - 2]; //上一页面
		console.log(perPage.data.allpicker.level)
		this.setData({
			level: perPage.data.allpicker.level
		})
		if (options.idx != undefined) {
			console.log(options.idx)
			var levelIdx = 0
			for (var k = 0; k < perPage.data.allpicker.level.length; k++) {
				if (perPage.data.allpicker.level[k].levelId == perPage.data.eductaionlist[options.idx].levelId) {
					levelIdx = k
				};
			}
			this.setData({
				idx: options.idx,
				startTime: perPage.data.eductaionlist[options.idx].startTime,
				endTime: perPage.data.eductaionlist[options.idx].endTime,
				major: perPage.data.eductaionlist[options.idx].major,
				levelIdx: levelIdx,
				schoolName: perPage.data.eductaionlist[options.idx].schoolName
			})

		}

	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	},
	startTimeChange: function(e) { //教育开始时间
		this.setData({
			startTime: e.detail.value.replace(/-/g, '.')
		})
	},
	endTimeChange: function(e) { //教育结束时间
		this.setData({
			endTime: e.detail.value.replace(/-/g, '.')

		})
	},
	levelChange: function(e) {
		this.setData({
			levelIdx: e.detail.value
		})
	},
	formSubmit(e) { //表单提交
		console.log('form发生了submit事件，携带数据为：', e.detail.value)
		console.log(e.detail.value)
		var pages = getCurrentPages(); //当前页面
		var perPage = pages[pages.length - 2]; //上一页面
		var list = perPage.data.teacherEduList;


		var showlist = perPage.data.eductaionlist;
		console.log('push before', showlist);
		
		if (this.data.idx) {
			console.log(this.data.level)


			list[this.data.idx] = e.detail.value

			var detailVal = e.detail.value;
			detailVal.level = this.data.level[e.detail.value.levelId].level
			detailVal.levelId = this.data.level[e.detail.value.levelId].levelId

			showlist[this.data.idx] = detailVal
		} else {
			console.log('no index');
			// list.push(e.detail.value)
			// console.log('list', list)

			var detailVal = e.detail.value;
			detailVal.level = this.data.level[e.detail.value.levelId].level
			detailVal.levelId = this.data.level[e.detail.value.levelId].levelId

			showlist.push(detailVal)
			console.log('showList', showlist)
		}

		console.log(showlist)
		perPage.setData({
			// teacherEduList: list,
			eductaionlist: showlist
		})
		wx.navigateBack({
			delta: 1
		})
	},
	formReset() {
		console.log('form发生了reset事件')
	}
})
